package com.redtea.lgp.usermanager.controller;

import com.redtea.lgp.usermanager.domain.bo.UserDeptBo;
import com.redtea.lgp.usermanager.domain.vo.UserInfoVo;
import com.redtea.lgp.usermanager.service.ILoginService;
import com.ruoyi.common.core.domain.R;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @program: StudySpringBoot
 * @ClassName UserController
 * @author: LGP
 * @create: 2024-04-12 17:28
 * @description:
 **/

@RequiredArgsConstructor
@RequestMapping("/public/user")
@RestController
public class UserController {

    private final ILoginService iLoginService;

    @GetMapping()
    public R<String> test(){
        return R.ok("获取测试");
    }
    @GetMapping("/getUserInfo")
    public R<UserInfoVo> getUserInfo(@RequestParam(value = "userId") Long id){
        UserInfoVo userInfoById = iLoginService.getUserInfoById(id);
        return R.ok(userInfoById);
    }

    @GetMapping("/getUserInfoByPathId/{id}")
    public R<UserInfoVo> getUserInfoByPathId(@NotNull(message = "用户id不能为空") @PathVariable Long id){
        UserInfoVo userInfoById = iLoginService.getUserInfoById(id);
        return R.ok(userInfoById);
    }

    @GetMapping("/getUserInfoList")
    public R<List<UserInfoVo>> getUserInfo(){
        List<UserInfoVo> userInfoList = iLoginService.getUserInfoList();
        //需要使用@RestController，@Controller时返时前端报url 404；
        return R.ok(userInfoList);
    }

    @PostMapping("/addUser")
    public R<Boolean> addUser(@RequestBody UserDeptBo userDeptBo){
        Boolean addResult = iLoginService.addUser(userDeptBo);
        return R.ok(addResult);
    }

    @PostMapping("/addUserList")
    public R<Boolean> addUserList(@RequestBody List<UserDeptBo> userDeptBos){
        Boolean addResult = iLoginService.batchAddUser(userDeptBos);
        return R.ok(addResult);
    }

    @PutMapping("/updateUser")
    public R<Boolean> updateUser(@RequestBody UserDeptBo userDeptBo){
        Boolean addResult = iLoginService.updateUser(userDeptBo);
        return R.ok(addResult);
    }

    @PutMapping("/updateUserList")
    public R<Boolean> updateUserList(@RequestBody List<UserDeptBo> userDeptBo){
        Boolean addResult = iLoginService.batchUpdateUser(userDeptBo);
        return R.ok(addResult);
    }

    @DeleteMapping("/delUser")
    public R<Boolean> delUser(@RequestBody UserDeptBo userDeptBo){
        Boolean addResult = iLoginService.delUser(userDeptBo);
        return R.ok(addResult);
    }

    @DeleteMapping("/delUserList")
    public R<Boolean> delUserList(@RequestBody List<UserDeptBo> userDeptBos){
        Boolean aBoolean = iLoginService.batchDelUser(userDeptBos);
        return R.ok(aBoolean);
    }

}
